package me.zhengjie.modules.system.rest.machine;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.base.Code;
import me.zhengjie.modules.system.domain.req.SysUserBusinessReqDTO;
import me.zhengjie.modules.system.domain.req.SysUserBusinessReqQueryDTO;
import me.zhengjie.modules.system.domain.rsp.SysUserBusinessRspDTO;
import me.zhengjie.modules.system.service.SysUserBusinessService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wx
 * @email
 * @date 2025-02-19 09:45:51
 */
@RestController
@RequestMapping("api/sysUserBusiness")
@Api(tags = "企业信息")
@RequiredArgsConstructor
public class SysUserBusinessController {

    private final SysUserBusinessService sysUserBusinessService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @PostMapping("/page")
    public PageResult<SysUserBusinessRspDTO> page(@RequestBody SysUserBusinessReqQueryDTO reqQueryDTO) {
        return sysUserBusinessService.findAll(reqQueryDTO);
    }


    /**
     * 保存
     */
    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public ResponseEntity<Boolean> save(@RequestBody SysUserBusinessReqDTO reqDTO) {
        sysUserBusinessService.save(reqDTO);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存或者修改")
    @PostMapping("/saveOrUpdate")
    public ResponseEntity<Boolean> saveOrUpdate(@RequestBody SysUserBusinessReqDTO reqDTO) {
        sysUserBusinessService.saveOrUpdate(reqDTO);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody SysUserBusinessReqDTO reqDTO) {
        sysUserBusinessService.update(reqDTO);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);

    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody Code code) {
        sysUserBusinessService.delete(code);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 主键查询
     */
    @ApiOperation(value = "主键查询")
    @PostMapping("/findById")
    public ResponseEntity<SysUserBusinessRspDTO> findById(@RequestBody Code code) {
        return new ResponseEntity<>(sysUserBusinessService.findById(code), HttpStatus.OK);
    }
}
